//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.yang.newcustomcuilian.particleseffect;

import java.util.Iterator;
import com.yang.newcustomcuilian.NewCustomCuiLian;
import com.yang.newcustomcuilian.language.Language;
import com.yang.newcustomcuilian.level.Level;
import com.yang.newcustomcuilian.listeners.SuitEffectListener;
import com.yang.newcustomcuilian.newapi.NewAPI;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class CheckThread extends Thread {
    public LivingEntity le;

    public CheckThread(LivingEntity le) {
        this.le = le;
    }

    public void run() {
        SuitEffectListener.lock.lock();

        try {
            ParticlesEffectManager pem = new ParticlesEffectManager();
            Level minLevel = NewAPI.getMinLevel(NewAPI.addAll(NewAPI.getItemInHand(this.le), this.le.getEquipment().getHelmet(), this.le.getEquipment().getChestplate(), this.le.getEquipment().getLeggings(), this.le.getEquipment().getBoots(), NewAPI.getItemInOffHand(this.le)));
            if (minLevel.levelValue != -1 && minLevel.canUsingSuitEffect) {
                if (((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get(minLevel.levelValue)).suitpotion.potionEffectList != null) {
                    Iterator var11 = ((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get(minLevel.levelValue)).suitpotion.potionEffectList.iterator();

                    while(var11.hasNext()) {
                        String s = (String)var11.next();
                        String tzxg = s.split(" ")[0];
                        this.le.addPotionEffect(new PotionEffect(PotionEffectType.getByName(tzxg), 60, Integer.parseInt(s.split(" ")[1])), true);
                    }

                    if (SuitEffectListener.canUseParticlesEffect) {
                        pem.Draw_Wings(this.le, minLevel.levelValue);
                    }

                    if (!NewCustomCuiLian.playerSuitEffectList.containsKey(this.le.getUniqueId())) {
                        if (this.le.getType() == EntityType.PLAYER) {
                            this.le.sendMessage(Language.TZXG_TRUE.replace("%s", (CharSequence)((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get(minLevel.levelValue)).levelString.get(0)));
                        }

                        NewCustomCuiLian.playerSuitEffectList.put(this.le.getUniqueId(), minLevel.levelValue);
                        NewCustomCuiLian.playerSuitEffectHealthList.put(this.le.getUniqueId(), NewAPI.getMaxHealth(this.le));
                        NewAPI.setMaxHealth(this.le, NewAPI.getMaxHealth(this.le) + (double)((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get(minLevel.levelValue)).suitpotion.suitHp);
                    }
                } else if (NewCustomCuiLian.playerSuitEffectList.containsKey(this.le.getUniqueId())) {
                    if (this.le.getType() == EntityType.PLAYER) {
                        this.le.sendMessage(Language.TZXG_FALSE.replace("%s", (CharSequence)((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get((Integer)NewCustomCuiLian.playerSuitEffectList.get(this.le.getUniqueId()))).levelString.get(0)));
                    }

                    NewAPI.setMaxHealth(this.le, 30.0D);
                    NewCustomCuiLian.playerSuitEffectList.remove(this.le.getUniqueId());
                }
            } else if (NewCustomCuiLian.playerSuitEffectList.containsKey(this.le.getUniqueId())) {
                if (this.le.getType() == EntityType.PLAYER) {
                    this.le.sendMessage(Language.TZXG_FALSE.replace("%s", (CharSequence)((Level)NewCustomCuiLian.customCuilianManager.customCuilianLevelList.get((Integer)NewCustomCuiLian.playerSuitEffectList.get(this.le.getUniqueId()))).levelString.get(0)));
                }

                Double health = (Double)NewCustomCuiLian.playerSuitEffectHealthList.get(this.le.getUniqueId());
                if (health != null) {
                    NewAPI.setMaxHealth(this.le, health);
                }

                NewCustomCuiLian.playerSuitEffectHealthList.remove(this.le.getUniqueId());
                NewCustomCuiLian.playerSuitEffectList.remove(this.le.getUniqueId());
            }
        } catch (NumberFormatException var9) {
            throw new RuntimeException(var9);
        } finally {
            SuitEffectListener.lock.unlock();
        }

    }
}
